# ################################################################ #
# latex.make                                                       #
#                                                                  #
# Common makefile for latex documents                              #
#                                                                  #
# (c) 2002-2003 Wouter Caarls, Delft University of Technology      #
# ################################################################ #

# Variables ###################################################### #

MAKEFILE_DEPS = Makefile $(SHARE)/vars.make $(SHARE)/include.make $(SHARE)/latex.make $(SHARE)/latex.depend

# Compilation #################################################### #

.SECONDARY:

$(filter-out $(OVERRIDE_TARGETS), all): $(NAME).ps

$(filter-out $(OVERRIDE_TARGETS), %.pdf): %.ps2pdf
	$(PS2PDF) $< $@

$(filter-out $(OVERRIDE_TARGETS), %.ps): %.dvi
	$(DVIPS) -o $@ $<

$(filter-out $(OVERRIDE_TARGETS), %.ps2pdf): %.dvi
	$(DVIPS) -Ppdf -o $@ $<

$(filter-out $(OVERRIDE_TARGETS), %.dvi): %.tex %.bib $(MAKEFILE_DEPS)
	$(LATEX) $*
	$(BIBTEX) $*
	$(LATEX) $*
	$(LATEX) $*

$(filter-out $(OVERRIDE_TARGETS), %.dvi): %.tex $(MAKEFILE_DEPS)
	$(LATEX) $*
	$(LATEX) $*

$(filter-out $(OVERRIDE_TARGETS), %.eps): %.fig $(MAKEFILE_DEPS)
	$(FIG2DEV) -L eps -z A4 $< $@

# Administration ################################################# #

$(filter-out $(OVERRIDE_TARGETS), clean): force
	rm -rf core $(NAME).ps $(NAME).pdf $(NAME).ps2pdf $(NAME).dvi *~ *.aux *.bbl *.blg *.log *.toc *.d $(NAME)-$(MAJOR).$(MINOR).$(REVISION) $(NAME)-$(MAJOR).$(MINOR).$(REVISION).tar $(NAME)-$(MAJOR).$(MINOR).$(REVISION).tar.gz

$(filter-out $(OVERRIDE_TARGETS), install): subdirs.install ;
$(filter-out $(OVERRIDE_TARGETS), uninstall): subdirs.uninstall ;

# Distribution ################################################### #

$(filter-out $(OVERRIDE_TARGETS), subdist): clean subdirs.dist latex.subdist;
$(filter-out $(OVERRIDE_TARGETS), latex.subdist): force
	mkdir $(DISTDIR)
	cp `find . -maxdepth 1 -name "*.tex" -o -name "*.fig" -o -name "*.sty" -o -name "*.bib" -o -name "*.bst" -o -name "*.cls"` $(DISTDIR)
	cp $(MAKEFILE_DEPS) $(DISTDIR)/$(SHAREDISTDIR)
ifdef DISTFILES
	cp --parent $(DISTFILES) $(DISTDIR)
endif
	sed -e "s/.*SHARE *=.*/SHARE = $(SEDSHAREDISTDIR)/" Makefile > $(DISTDIR)/Makefile

# Dependencies ################################################### #

$(filter-out $(OVERRIDE_TARGETS), %.d): %.tex
	$(SHARE)/latex.depend $*

ifeq ($(filter clean install uninstall dist subdist undist distclean realclean, $(MAKECMDGOALS)),)
-include $(NAME).d
endif
